# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=laminar
pkgver=1.3
pkgrel=4
pkgdesc="Fast and lightweight Continuous Integration server"
url="https://laminar.ohwg.net/"
license="GPL-3.0-or-later"
arch="all !armhf !armv7 !x86" # FTBFS on 32-bit arches
arch="$arch !ppc64le !s390x" # tests fail
install="$pkgname.pre-install"
makedepends="clang cmake samurai boost-dev capnproto-dev rapidjson-dev sqlite-dev gtest-dev"
subpackages="
	$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
_vue_ver=2.6.12
_ansi_up_ver=4.0.4
_chart_ver=3.9.1
source="https://github.com/ohwgiles/laminar/archive/$pkgver/laminar-$pkgver.tar.gz
	vue-$_vue_ver.min.js::https://cdnjs.cloudflare.com/ajax/libs/vue/$_vue_ver/vue.min.js
	ansi_up-$_ansi_up_ver.js::https://raw.githubusercontent.com/drudru/ansi_up/v$_ansi_up_ver/ansi_up.js
	https://github.com/chartjs/Chart.js/releases/download/v$_chart_ver/chart.js-$_chart_ver.tgz
	$pkgname.initd
	no-network.patch
	laminard-location.patch
	libstdc++13.patch
	musl.patch
	"

prepare() {
	default_prepare

	sed -i 's/^#LAMINAR/#export LAMINAR/g' etc/laminar.conf

	install -Dm644 "$srcdir"/vue-$_vue_ver.min.js build/js/vue.min.js
	install -Dm644 "$srcdir"/ansi_up-$_ansi_up_ver.js build/js/ansi_up.js
	install -Dm644 "$srcdir"/package/dist/chart.min.js build/js/Chart.min.js
}

check() {
	./build/laminar-tests
}

build() {
	CC=clang CXX=clang++ \
		cmake -G Ninja -B build \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DLAMINAR_VERSION=$pkgver \
		-DSYSTEMD_UNITDIR=/no_systemd \
		-DBUILD_TESTS=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname

	# we don't use systemd
	rm -r "$pkgdir"/no_systemd
}

sha512sums="
cdcf3544e641bf6250361e8b693de90300014d86ed1053e65a2670243b8901707c16c274ea63cebb613943fa81a9a9037778a00ad4a1296c3f7efb2888fe52a3  laminar-1.3.tar.gz
04a6d247e71fcb12dd300b04d2768b45e1522e0f3fa636e07f11e1fe4fe4502f361f2eebe87b51e612e1a1b6a59f681c4efce4cb27a1add444763a6c430cb627  vue-2.6.12.min.js
34c8cb74f687abc77ab84c4a504a04d9b334e9224ceffd35e6e3b31f0ff1c59ee3ddb239e5d731b6839de00485d47db34f338e2943affba04a80f6ecb43eafc3  ansi_up-4.0.4.js
468d896cb9af83cde05c5e45e2c9e2690fa54db4afd7c13e4c87f670e7a21f522a7763c614eb5e9be0d4b9f319b02270144ef2c0f3a97d7141c114c6abb761eb  chart.js-3.9.1.tgz
c203f573cc44a76f3f66f170b7baa3d9784ceae7532f872985a071e1b06cd1d436ff3e45f39260cdb0333b9bb64312fcbff6eb3ac1230711636f57c92d4922ff  laminar.initd
f5845eaa845358a55b549632f85d8cdd29fe09592ef99ec5df0f22493e4a2b00161dca6266f4180f54a90aae7b5826e3751fe9ca5f23ff1aec0b5817b24bbf6a  no-network.patch
cef3436e6123c2fc71cab4cb565db625cf60e8311410fd08548f140c42745de1114e950b1459011f70bbdf45c220e63db2798b1cdeb01e82df09719208ef9620  laminard-location.patch
9c0b11f0c141c716185992f49a6ebbc3e168a7ab91de8ac70be890ecf003e67976ee41952d76bfc668144d2520e1434a2b6c74ec63803191d6163716f38993d0  libstdc++13.patch
6b532e15a9f308a7d1c51c2c346492c0e49710b813efb1cd17ca3520479ab700d844908119a44c8e3eca3fa0d3798d98bc0c572a0ea3e865c6694eda9a656b73  musl.patch
"
